﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.sysDAL;
using dhDataAcess.Model;
using dhDataAcess.dataAcess.sysDataSetTableAdapters;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.baseBLL;

namespace dhSystemBLL.basicData
{
   public  class workerListBLL
    {
       private workerListTableAdapter _workerListAdapter = null;
       private workerListTableAdapter  workerListAdapter
        {
            get
            {
                if (_workerListAdapter == null) _workerListAdapter = new workerListTableAdapter ();
                return _workerListAdapter;
            }
        }
        /// <summary>
        /// 查询职员表格
        /// </summary>
        /// <returns></returns>

       public sysDataSet.workerListDataTable  getworkerListAll()
        {
            try
            {
                return workerListAdapter.GetDataworkerListAll();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 根据职员名称查询表
        /// </summary>
        /// <param name="groupNum"></param>
        /// <returns></returns>

       public sysDataSet.workerListDataTable getworkerListAll(string name)
        {
            try
            {

                return workerListAdapter.GetDataworkerListByName(name);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }




        /// <summary>
        /// 插入信息
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int workerListInsert(workerListModel row)
        {
            int i = 0; 
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();

                workerListDAL workerList = new workerListDAL(tn, conn);
                workerList.workerListInsert(row);
                tn.Commit();
                return i;
            }

            catch (SqlException ex)
            {
                tn.Rollback();
                if (ex.Number == 2627)
                {
                    throw new Exception("这个职员工号已经存在");
                }

                throw new Exception(ex.Number.ToString() + ex.Message.ToString());
            }
            catch (Exception ex)
            {
                tn.Rollback();

                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

       public int workerListUpdate(workerListModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                workerListDAL workerList = new workerListDAL(tn, conn);
                workerList.workerListUpdate(row);
                tn.Commit();
                return i;
            }

            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="itemNum"></param>
        /// <returns></returns>

       public int workerListDel(string workerNum)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                workerListDAL workerList = new workerListDAL(tn, conn);
                workerList.workerListDel(workerNum);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
       
    }
}
